/**
 * Definition for singly-linked list.
 * function ListNode(val, next) {
 *     this.val = (val===undefined ? 0 : val)
 *     this.next = (next===undefined ? null : next)
 * }
 */
/**
 * @param {ListNode} head
 * @return {ListNode}
 */
// 使用数组，快速解答
var reverseList = function (head) {
  let temp = head;
  let arr = [];
  while (temp) {
    arr.push(temp.val);
  }
  if (arr.length === 1) return new ListNode(arr[0]);

  arr.reverse();
  let res = new ListNode(arr[0]);
  temp = res;
  for (let i = 1; i < arr.length; i++) {
    temp.next = new ListNode(arr[i]);
    temp = temp.next;
  }
  return res;
};

// 双指针
